﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;
using System.IO;

namespace Mingbo.Library
{
    /// <summary>
    /// 测试
    /// http://api.t.sina.com.cn/statuses/public_timeline.(json|xml）
    /// </summary>
    public class GetPublicMsg
    {
        string url = GetURL.URL_PublicMsg;
        string appkey="631859723";

        public string GetPubMsg() 
        {
           string url =  string.Format("{0}?source={1}&count=10",GetURL.URL_PublicMsg,appkey);
           //HttpWebRequest wq =(HttpWebRequest)HttpWebRequest.Create(new Uri(url));
           //wq.Method = "get";
           WebClient wc = new WebClient();
           wc.OpenReadCompleted += new OpenReadCompletedEventHandler(delegate(object sender, OpenReadCompletedEventArgs e) {
               StreamReader sr =new StreamReader(e.Result);
               string result =sr.ReadToEnd();

           });
            
           //StreamReader sr = wq.GetRequestStream().Read;

            return string.Empty;
        }
        /// <summary>
        /// HTTP普通验证(Basic Authentication)方式
        /// </summary>
        /// <param name="url">API URL</param>
        /// <param name="httpRequestMethod)">HTTP请求方式：GET或POST</param>
        /// <returns></returns>
        //private static WebRequest BasicAuthorizationRequest(string url, string httpRequestMethod)
        //{
        //    CredentialCache mycache = new CredentialCache();
        //    mycache.Add(new Uri(url), "Basic", new NetworkCredential(UserInfo.UserName, UserInfo.Password));
        //    WebRequest myReq = WebRequest.Create(url);
        //    myReq.Credentials = mycache;
        //    myReq.Headers.Add("Authorization", "Basic " + Convert.ToBase64String(new ASCIIEncoding().GetBytes(UserInfo.UserNamePassword)));
        //    myReq.Method = httpRequestMethod;
        //    return myReq;
        //}

    }
    

    /// <summary>
    /// 获取各个接口的URL
    /// </summary>
    public class GetURL
    {
        /// <summary>
        /// 获取返回最新的20条公共微博。返回结果非完全实时，最长会缓存60秒
        /// </summary>
        public static string URL_PublicMsg = "http://api.t.sina.com.cn/statuses/public_timeline.json";

    }
}
